package com.ewins.weatherdataclient.common;

import com.ewins.weatherdatautils.utils.Configuration;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;

import java.io.File;

/**
 * 常量数据
 */
public class Constant {
	public static String root = System.getProperty("user.dir") + File.separator + "config" + File.separator + "config.properties";
	public  static String UserName = Configuration.GetValueByKey(root, "UserName");
	public  static String UserPassword = Configuration.GetValueByKey(root, "UserPassword");

	/**
	 * 下载文件的url跟目录
	 */
	public static String DownLoadFileUrl = Configuration.GetValueByKey(root, "DownLoadFileUrl");

	/**
	 * 更新下载目录的url
	 */
	public  static  String DownLoadCatalogUrl =Configuration.GetValueByKey(root, "DownLoadCatalogUrl");

	/**
	 * 单文件下载需要开启线程数目
	 */
	public static int FileDownloadThreadCount = Integer.parseInt(Configuration.GetValueByKey(root, "FileDownloadThreadCount"));

	/**
	 * 线程缓冲池中最大的线程数目
	 */
	public static int ThreadPoolMaxThreadCount = Integer.parseInt(Configuration.GetValueByKey(root, "ThreadPoolMaxThreadCount"));

	/**
	 * 可开启的下载线程数目
	 */
	public static int DownLoadThreadCount = Integer.parseInt(Configuration.GetValueByKey(root, "DownLoadThreadCount"));

	/**
	 * 单次访问http下载数据的最大值
	 */
	public static int HttpDownLoadMaxSize = 10240;
	/**
	 * 连接超时(豪秒)
	 */
	public static  int HttpConnectTimeout = Integer.parseInt(Configuration.GetValueByKey(root, "HttpConnectTimeout"));
	/**
	 * 读取超时(豪秒)
	 */
	public static  int HttpReadTimeout = Integer.parseInt(Configuration.GetValueByKey(root, "HttpReadTimeout"));

	/**
	 * 轮询更新下载目录的时间(秒)
	 */
	public static int Update_DownLoad_Catalog_Time = Integer.parseInt(Configuration.GetValueByKey(root, "Update_DownLoad_Catalog_Time"));

	// log配置文件路径
	public static String CONFIG_PATH_LOG = System.getProperty("user.dir")
			+ File.separator + "config" + File.separator + "log4j.properties";


	// 下载文件本地存放路径
	public static String Local_DownLoad_Path = System.getProperty("user.dir")
			+ File.separator + "download" ;

	public static Logger log= Logger.getLogger(Constant.class);

	public static void load() {
		try {
			String confPath = System.getProperty("user.dir") + File.separator + "config" + File.separator;
			String root = confPath + "config.properties";
			PropertyConfigurator.configure(confPath + "log4j.properties");
			UserName = Configuration.GetValueByKey(root, "UserName");
			UserPassword = Configuration.GetValueByKey(root, "UserPassword");
			DownLoadFileUrl = Configuration.GetValueByKey(root, "DownLoadFileUrl");
			DownLoadCatalogUrl = Configuration.GetValueByKey(root, "DownLoadCatalogUrl");
			FileDownloadThreadCount = Integer.parseInt(Configuration.GetValueByKey(root, "FileDownloadThreadCount"));
			ThreadPoolMaxThreadCount =Integer.parseInt(Configuration.GetValueByKey(root, "ThreadPoolMaxThreadCount"));
			DownLoadThreadCount = Integer.parseInt(Configuration.GetValueByKey(root, "DownLoadThreadCount"));
			Update_DownLoad_Catalog_Time = Integer.parseInt(Configuration.GetValueByKey(root, "Update_DownLoad_Catalog_Time"));
			Local_DownLoad_Path = System.getProperty("user.dir")
					+ File.separator + Configuration.GetValueByKey(root, "Local_DownLoad_Path") + File.separator;
					}
		catch (Exception e){
			log.error(e.getMessage());
		}
	}
}
